package com.pjb.springbootjjwt.store.utils;

import com.pjb.springbootjjwt.store.Sql;
import com.pjb.springbootjjwt.store.entity.Table;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class SqlUtil {

    /**
     * 获取字段初始序号
     *
     * @param alias
     * @param tables
     * @return
     */
    public static int getInitIndex(String alias, List<Table> tables) throws IOException {
        int init = 0;
        for (Table table : tables) {
            if (alias.equals(table.getAlias())) return init;

            init += Sql.getInstance().getFields(table).size();
        }
        return 0;
    }

    /**
     * 获取字段序号
     *
     * @param arr
     * @param tables
     * @return
     * @throws IOException
     */
    public static List<Integer> getIndex(String[] arr, List<Table> tables) throws IOException {
        List<Integer> r = new ArrayList<>();
        for (String s : arr) {
            int index = Sql.getInstance().getFieldIndexByMultiTables(s, tables);
            r.add(index);
        }
        return r;
    }

}
